import { defHttp } from '/@/utils/http/axios';
import {
  LoginParams,
  LoginResultModel,
  GetUserInfoModel,
  UserParams,
  UserListGetResultModel,
  CreateUserParam,
  UpdateUserParam, PwdParam,
} from './model/userModel';

import { ErrorMessageMode } from '/#/axios';
enum Api {
  Login = '/system/passport/login',
  Logout = '/system/passport/logout',
  ChangePwd = '/system/passport/changePwd',
  GetUserInfo = '/system/users/getUserInfo',
  GetPermCode = '/system/users/getPermCode',
  GetUserList = '/system/users/getUserListByPage',
  CreateUser = '/system/users/createUser',
  UpdateUser = '/system/users/updateUser',
}

/**
 * @description: user login api
 */
export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<LoginResultModel>(
    {
      url: Api.Login,
      params,
    },
    {
      errorMessageMode: mode,
    }
  );
}

/**
 * @description: getUserInfo
 */
export function getUserInfo() {
  return defHttp.get<GetUserInfoModel>({ url: Api.GetUserInfo });
}

export function getPermCode() {
  return defHttp.get<string[]>({ url: Api.GetPermCode });
}

export function doLogout() {
  return defHttp.get({ url: Api.Logout });
}

export const getUserList = (params: UserParams) =>
  defHttp.get<UserListGetResultModel>({ url: Api.GetUserList, params });

export const createUserAccount = (params?: CreateUserParam) =>
  defHttp.post({ url: Api.CreateUser, params: params });

export const updateUserAccount = (params?: UpdateUserParam) =>
  defHttp.post({ url: Api.UpdateUser, params: params });

export const changePwd = (params?: PwdParam) =>
  defHttp.post({ url: Api.ChangePwd, params: params });
